/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.pc9.pswing.util;

import br.com.pc9.pswing.components.filebrowser.PFileView;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.swing.Icon;

/**
 *
 * @author paulocanedo
 */
public class SystemUtilsOS {

    private final static String userHome = System.getProperty("user.home");
    private final static File fileUserHome = new File(userHome);
    private final static String osname = System.getProperty("os.name").toLowerCase();
    private final static String username = System.getProperty("user.name").toLowerCase();
    private static OperationSystemUtilInterface operationSystemUtil;

    private SystemUtilsOS() {
    }
    
    public static boolean isWindowsXP() {
        return osname.indexOf("windows xp") != -1;
    }

    public static boolean isWindows() {
        return osname.indexOf("windows") != -1;
    }

    public static boolean isMac() {
        return osname.indexOf("mac") != -1;
    }

    public static boolean isLinux() {
        return osname.indexOf("linux") != -1;
    }
    
    public static boolean isAdmin() {
        return (username.indexOf("root") != -1) || (username.indexOf("administrator") != -1);
    }
    
    private static OperationSystemUtilInterface getOperationSystemUtil() {
        if (operationSystemUtil == null) {
            if (isLinux()) {
                operationSystemUtil = new LinuxGnomeUtil();
            } else if(isWindows()) {
                operationSystemUtil = new WindowsUtil();
            } else if(isMac()) {
                operationSystemUtil = new MacOSXUtil();
            }
        }
        return operationSystemUtil;
    }

    public static List<PFileView> getFavoritePlaces() throws IOException {
        return getOperationSystemUtil().getFavoritePlaces();
    }

    public static String getThemeName() throws Exception {
        return getOperationSystemUtil().getThemeName();
    }

    public static UserFolders getUserFolders() throws IOException {
        return getOperationSystemUtil().getUserFolders();
    }

    public static Icon getSystemIcon(String category, String name, int size) {
        return getOperationSystemUtil().getSystemIcon(category, name, size);
    }

    public static String getUserHome() {
        return userHome;
    }

    public static File getUserHomeAsFile() {
        return fileUserHome;
    }

    public static boolean isLeftDoubleClick(MouseEvent e) {
        return (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2);
    }
    
}
